/*
 * HoldLotAction.java
 *
 * Created on June 9, 2002, 1:23 AM
 */

package com.scalar.chiptrack.operations.process.actions;

import java.util.HashMap;
import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
//import org.apache.struts.action.ForwardingActionForward;

//import com.scalar.ScalarException;
import com.scalar.chiptrack.ChipTrackAction;
//import com.scalar.chiptrack.db.DBTransaction;
//import com.scalar.chiptrack.users.User;
//import com.scalar.chiptrack.commons.SessionKeys;
import com.scalar.chiptrack.operations.process.forms.WipProcessFlowForm;
import com.scalar.chiptrack.operations.process.dao.FabDAO;
import com.scalar.chiptrack.operations.process.dao.PartNumber;
import com.scalar.chiptrack.operations.process.dao.ProductDao;

/**
 *
 * @author  Mallikarjun
 * @version 1.0
 */
public class PcmDataAction extends ChipTrackAction{

       public ActionForward execute (ActionMapping mapping,
                                      ActionForm form,
                                      HttpServletRequest request,
                                      HttpServletResponse response)
                                      throws Exception {

            ActionForward actionForward = null;
            WipProcessFlowForm wipFlowForm = (WipProcessFlowForm)form;
            boolean success = false;
            HashMap errors = new HashMap();

            String productId = wipFlowForm.getPartNumber();
            String flowaction = request.getParameter("flowaction");
            String productName = null;

            ArrayList partNumberList = ProductDao.getPartNumber ( "FAB" );
            PartNumber partNumber = null;
            ArrayList partNumberSelectList = new ArrayList ();
            for ( int i = 0; i < partNumberList.size (); i++ )
            {
               partNumber = ( PartNumber ) partNumberList.get ( i );
               partNumberSelectList.add ( new org.apache.struts.util.LabelValueBean ( partNumber.getPartNumber (), partNumber.getProcessStepId ()  ) );
            }
            request.setAttribute("fabPartNumbers", partNumberSelectList );

            String from = null;
			//System.out.println("Flowaction = "+flowaction);

            if(flowaction == null){
                from = "FAB_LOTS";
                request.setAttribute("from", from);
                actionForward = mapping.findForward("show");
            }

            if("FAB_LOTS".equalsIgnoreCase(flowaction)){
                String showList = "VIEW_LOTS";
                from = "FAB_LOTS";
                String processStepId = request.getParameter("processStepId");
                productName = request.getParameter("productName");

                //System.out.println("Process StepID = "+ processStepId);
                request.setAttribute("fabLotNumbers", FabDAO.getFabLotNumbers(processStepId));
                request.setAttribute("productName", productName);
                request.setAttribute("showList", showList);
                request.setAttribute("from", from);
                actionForward = mapping.findForward("view");
            }

            return actionForward;
       }
}